package com.fisglobal.ewire;

public class Element  implements Cloneable
{
	private String defaultValue;
	private String value;
	private String appendValue;
	private int index;
	private String functionName;
	
	public Element(String v, String dv, String av)
	{
		index = -1;
		value = v;
		defaultValue = dv;
		appendValue = av;
	}
	
	public Element(int i, String fn, String dv, String av)
	{
		index = i;
		functionName = fn;
		defaultValue = dv;
		appendValue = av;
	}
	
	public String getDefaultValue()
	{
		return (defaultValue==null?"":defaultValue);
	}
	
	public void setDefaultValue(String defaultValue)
	{
		this.defaultValue = defaultValue;
	}
	
	public String getValue()
	{
		return (value==null?"":value);
	}
	
	public void setValue(String value)
	{
		this.value = value;
	}
	
	public String getAppendValue()
	{
		return (appendValue==null?"":appendValue);
	}
	
	public void setAppendValue(String appendValue)
	{
		this.appendValue = appendValue;
	}
	
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		
		if (isEmpty(value))
		{
			if (isEmpty(defaultValue))
			{
				sb.append("");
			}
			else
			{
				sb.append(defaultValue);
			}
		}
		else
		{
			sb.append(value);
		}
		
		if (appendValue != null)
		{
			sb.append(appendValue);
		}
		
		return sb.toString();
	}

	public int getIndex()
	{
		return index;
	}

	public void setIndex(int index)
	{
		this.index = index;
	}
	
	private static boolean isEmpty(String s)
	{
		if (s == null)
		{
			return true;
		}
		
		if (s.trim().length() == 0)
		{
			return true;
		}
		
		return false;
	}
	
	public Object clone()
	{
		return (Object)new Element(this.index, this.functionName, this.defaultValue, this.appendValue);
	}

	public String getFunctionName()
	{
		return functionName;
	}

	public void setFunctionName(String functionName)
	{
		this.functionName = functionName;
	}
}
